package com.ruicar.afs.cloud.afscase.remind.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.afscase.remind.entity.CaseRemindDetail;
import com.ruicar.afs.cloud.afscase.remind.mapper.RemindMapper;
import com.ruicar.afs.cloud.afscase.remind.service.RemindService;
import com.ruicar.afs.cloud.common.modules.afscorebusiness.enums.RemindOperateTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @Description
 * @Author Peng_Jinbo
 * @Date 2020/05/30 13:34
 */
@Service
@AllArgsConstructor
@Data
@Slf4j
public class RemindServiceImpl extends ServiceImpl<RemindMapper, CaseRemindDetail> implements RemindService {
    @Override
    public Optional<CaseRemindDetail> queryNewestRemindOpt(String applyNo) {
        Optional retOpt = Optional.empty();
        if (StrUtil.isNotBlank(applyNo)) {
            retOpt = list(
                    Wrappers.<CaseRemindDetail>lambdaQuery()
                            .eq(CaseRemindDetail::getApplyNo, applyNo)
                            .eq(CaseRemindDetail::getOperationType, RemindOperateTypeEnum.PARSE.getValue())
                            .orderByDesc(CaseRemindDetail::getCreateTime)
            ).stream().findFirst();
        }
        return retOpt;
    }
}
